package main

import (
	"crypto/tls"
	"io/ioutil"
	"net"
	"os"
	"study/app2/xmpp"
)

/**
 * @author 172.17.0.3 07d335610935 ejabberdhost
 * @author 172.17.0.4 e3f3df2090b7 openfirehost
 * @author 10.100.139.93 yxhn-test-t3
 */
func main() {
	domain := "172.17.0.3"
	conf := &tls.Config{
		ServerName:         domain,
		InsecureSkipVerify: false,
	}
	c, err := net.Dial("tcp", "172.17.0.3:5222")
	if err != nil {
		println("Fatal error ", err.Error())
	}
	i, err := c.Write([]byte("<stream:stream to='172.17.0.3' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"))
	println(i, err.Error())
	conn := tls.Client(c, conf)
	xconf := &xmpp.Config{Conn: conn, SkipTLS: false}
	println(xconf)
	Conn, err := xmpp.Dial(domain+":5222", "admin", domain, "admin", "gsend", xconf)
	if err != nil {
		println("err 1 ", err.Error())
		return
	}

	if s, err := ioutil.ReadAll(os.Stdin); err == nil {
		println(err)
		Conn.Send("test1@"+domain, "chat", string(s[:len(s)-1]))
		return
	}
}
